﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
	
    <!-- Resource dictionary entries should be defined here. -->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Colors.xaml"/>
        <ResourceDictionary Source="ValidationToolTipTemplate.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <Style TargetType="{x:Type TextBox}">
        <Setter Property="Foreground">
            <Setter.Value>
                <SolidColorBrush Color="{StaticResource Application_Control_Foreground}"/>
            </Setter.Value>
        </Setter>
        <Setter Property="CaretBrush">
            <Setter.Value>
                <SolidColorBrush Color="{StaticResource Application_Control_Foreground}"/>
            </Setter.Value>
        </Setter>
		<Setter Property="Padding" Value="1"/>
		<Setter Property="AllowDrop" Value="true"/>
		<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
		<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
		<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Template" Value="{DynamicResource TextBoxTemplate}"/>
	</Style>

    <ControlTemplate x:Key="TextBoxTemplate" TargetType="{x:Type TextBox}">
        <Grid x:Name="RootElement">
    		<VisualStateManager.VisualStateGroups>
    			<VisualStateGroup x:Name="CommonStates">
    				<VisualState x:Name="Normal"/>
    				<VisualState x:Name="Disabled">
    					<Storyboard>
    						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
    							<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_TextBox_Foreground_Disabled}"/>
    						</ColorAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="ReadOnly">
    					<Storyboard>
    						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
    							<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_TextBox_Foreground_Disabled}"/>
    						</ColorAnimationUsingKeyFrames>
    					</Storyboard>
					</VisualState>
    				<VisualState x:Name="MouseOver">
    					<Storyboard>
    						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Border">
    							<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_TextBox_Background_Move}"/>
    						</ColorAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="FocusStates">
    				<VisualState x:Name="Unfocused">
    					<Storyboard>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="FocusVisualElement">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
    						</ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="Focused">
    					<Storyboard AutoReverse="True" RepeatBehavior="Forever">
    						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="FocusVisualElement">
    							<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    							<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.5"/>
    						</DoubleAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="ValidationStates">
    				<VisualState x:Name="Valid">
    					<Storyboard>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
    						</ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="InvalidFocused">
    					<Storyboard>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    						</ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToolTip.IsOpen)" Storyboard.TargetName="validationTooltip">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <sys:Boolean>true</sys:Boolean>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="InvalidUnfocused">
    					<Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ValidationErrorElement">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    		</VisualStateManager.VisualStateGroups>
            
    		<Border x:Name="Border" SnapsToDevicePixels="true" CornerRadius="2" BorderThickness="1">
    			<Border.BorderBrush>
    				<SolidColorBrush Color="{StaticResource Application_TextBox_BorderBrush}"/>
    			</Border.BorderBrush>
    			<Border.Background>
    				<SolidColorBrush Color="{StaticResource Application_TextBox_Background}"/>
    			</Border.Background>
    			<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}"/>
    		</Border>
            <Border x:Name="FocusVisualElement" BorderThickness="1" Margin="0" CornerRadius="2" Visibility="Visible" IsHitTestVisible="False" Opacity="0">
    			<Border.BorderBrush>
    				<SolidColorBrush Color="{StaticResource Application_Control_BorderBrush_Focus}"/>
    			</Border.BorderBrush>
    		</Border>
            <Border x:Name="ValidationErrorElement" BorderThickness="1" Margin="0" CornerRadius="2" Visibility="Collapsed" IsHitTestVisible="True">
                <Border.BorderBrush>
    				<SolidColorBrush Color="{StaticResource Application_TextBox_BorderBrush_ValidationError}"/>
    			</Border.BorderBrush>
                <ToolTipService.ToolTip>
                    <ToolTip x:Name="validationTooltip" Placement="Bottom"
						    Template="{DynamicResource ValidationToolTipTemplate}"
    					    PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
    					    DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                    </ToolTip>
                </ToolTipService.ToolTip>
            </Border>
    	</Grid>
    </ControlTemplate>
</ResourceDictionary>